package com.scau.XFourPOS.service.impl;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.scau.XFourPOS.dao.BaseDao;
import com.scau.XFourPOS.service.BaseService;
import com.scau.XFourPOS.utils.PageUtils;
/**
 * 基础service 所有service继承该类
 * 提供基础的实体操作方法
 * 使用HibernateDao<T,PK>进行业务对象的CRUD操作,子类需重载getEntityDao()函数提供该DAO.
 * 
 * @param <T>
 * @param <PK>
 */
public abstract class BaseServiceImpl<T> implements BaseService<T>{
	
	/**
	 * 子类需要实现该方法，提供注入的dao
	 * @return
	 */
	public abstract BaseDao<T> getEntityDao();
	
	@Transactional(readOnly = false)
	public T loadEntityById(final int id) {
		return getEntityDao().loadEntityById(id);
	}

	@Transactional(readOnly = false)
	public void saveEntity(final T entity) {
		getEntityDao().saveEntity(entity);;
	}
	
	@Transactional(readOnly = false)
	public void updateEntity(final T entity) {
		getEntityDao().updateEntity(entity);;
	}

	@Transactional(readOnly = false)
	public void deleteEntity(final T entity){
		getEntityDao().deleteEntity(entity);
	}
	
	@Transactional(readOnly = false)
	public void deleteEntityById(final int id){
		getEntityDao().deleteEntityById(id);
	}
	
	@Transactional(readOnly = true)
	public List<T> loadAll(){
		return getEntityDao().loadAll();
	}
	
	@Transactional(readOnly = true)
	public PageUtils<T> loadAllByPage(PageUtils<T> pageUtils){
		return getEntityDao().loadAllByPage(pageUtils);
	}
	@Transactional(readOnly = true)
	public boolean isExitEntity(String key,String value){
		return getEntityDao().isExitEntity(key, value);
	}
	@Transactional(readOnly = true)
	public T loadEntityByKey(String key, String value){
		return getEntityDao().loadEntityByKey(key, value);
	}
	@Transactional(readOnly = true)
	public PageUtils<T> loadByPageAndKey(PageUtils<T> pageUtils,String key,int value){
		return getEntityDao().loadByPageAndKey(pageUtils, key, value);
	}
}
